package com.da.lon.wang.xlg.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;

import com.da.lon.wang.xlg.MyApplication;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.util.ViewHolder;

import java.util.List;

public class NoneCartAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;

    private List<String> imgList;
    private List<String> nameList;
    private List<String> priceList;
    private List<String> pricespeList;
    private List<String> zkList;

    public NoneCartAdapter(Context context, List<String> nImgList,
                           List<String> nNameList, List<String> nPriceList,
                           List<String> nPricespeList, List<String> nZkList) {
        // TODO Auto-generated constructor stub

        inflater = LayoutInflater.from(context);

        this.context = context;

        this.imgList = nImgList;
        this.nameList = nNameList;
        this.priceList = nPriceList;
        this.pricespeList = nPricespeList;
        this.zkList = nZkList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return nameList != null ? nameList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return nameList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        try {
            convertView = inflater.inflate(R.layout.ouka_search_griditem, null);

            ImageView imgView = ViewHolder.get(convertView,
                    R.id.search_grid_img);
            TextView nameView = ViewHolder.get(convertView,
                    R.id.search_grid_name);
            TextView pricespeView = ViewHolder.get(convertView,
                    R.id.search_grid_pricespe);
            TextView priceView = ViewHolder.get(convertView,
                    R.id.search_grid_price);
            TextView zkView = ViewHolder.get(convertView, R.id.search_grid_zk);

            imgView.setScaleType(ScaleType.CENTER_CROP);
            MyApplication.loadImageByPicasso(context, imgList.get(position),
                    null, imgView, 0, 0, 0);
            nameView.setText(nameList.get(position));
            pricespeView.setText("￥" + pricespeList.get(position));
            priceView.setText("￥" + priceList.get(position));
            priceView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            zkView.setText(zkList.get(position) + "折");
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return convertView;
    }

}
